<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.infodms.dms.common.Constant"%>

<%
	String contextPath = request.getContextPath();
%>
<%@taglib uri="/jstl/cout" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<jsp:include page="${contextPath}/common/jsp_head_new.jsp" />
<title>批发申请</title>
</head>
<body onunload='javascript:destoryPrototype();' onload='checkFirst();'> 
<div class="wbox">
	<div class="navigation"><img src="<%=contextPath%>/img/nav.gif" />&nbsp;当前位置：  整车销售 &gt; 库存管理 &gt; 批发申请</div>
	<form id="fm" name="fm" method="post">
		<input type="hidden" name="curPage" id="curPage" value="1" />
		<input type="hidden" id="dlrId" name="dlrId" value="" />
		<table class="table_query" border="0">
		<c:if test="${returnValue==2}">
		<tr>
		<td  colspan="3"><font color="red">注意事项:</font></td>
	</tr>
		<tr>
		<td  colspan="3"><font color="red">1、大区内一级服务中心批发给一级服务中心——区域销售主管审核</font></td>
		</tr>
		<tr>
		<td  colspan="3"><font color="red">2、跨区或跨网批发——订单管理室赖从东审核。</font></td>
		</tr>
		<tr>
		<td  colspan="3"><font color="red">3、一级服务中心批发给二级经销商--无需审核，直接入二级经销商库房。</font></td>
		</tr>
		</c:if>
			<tr>
				<td width="20%" class="tblopt">
					<div align="right">
					<input type="radio" checked="checked"  name="flag"  onclick="toChangeMaterial(1);" />
						物料组选择：
					</div>
				</td>
				<td>
					<input type="text" id="materialCode" name="materialCode"  value=""  />
       				<input type="button" id="bt1" value="..." class="mini_btn"  onclick="showMaterialGroup('materialCode','','true','');" />
				</td>
				<td></td>
			</tr>
			<tr>
				<td width="20%" class="tblopt">
					<div align="right">
					<input type="radio"  name="flag"  onclick="toChangeMaterial(2);"/>
						&nbsp;&nbsp;&nbsp;物料选择：
					</div>
				</td>
				<td>
					<input type="text" id="materialCode__" name="materialCode__"  value=""  readonly="readonly"/>
       				<input type="button" id="bt2" value="..." class="mini_btn" disabled="disabled" onclick="showMaterial('materialCode__','','true','');" />
				</td>
				<td></td>
			</tr>
			<tr>
			<td align="right" width="20%">仓库名称：</td>
			<td>
  				<select id="warehouse__" name="warehouse__" >
  				<option value="">-请选择-</option>
  					<c:forEach var="W_warehouse" items="${list }">
						<option value="${W_warehouse.WAREHOUSE_ID }">${W_warehouse.WAREHOUSE_NAME }</option>
					</c:forEach>
  				</select>
  		    </td>
  		    </tr>
			<tr>
				<td width="20%" class="tblopt"><div align="right">VIN：</div></td>
				<td width="39%" >
      				<textarea id="vin" name="vin" cols="18" rows="3" ></textarea>
    			</td>
				<td class="table_query_3Col_input" >
					<input type="button" class="normal_btn" onclick="__extQuery__(1);" value="  查  询  " id="queryBtn" /> 
				</td>
			</tr>
		</table>
	<jsp:include page="${contextPath}/queryPage/orderHidden.html" />
	<jsp:include page="${contextPath}/queryPage/pageDiv.html" />
	</form>
</div>
<form  name="form1" id="form1">
<table class="table_query" width="85%" align="center" border="0"  id="roll">
	<tr>
		<td width="27%"  align="right"><input type="radio" id="rd1" name=chngType value="1" checked="checked" onclick="checkFirst();"/>调入经销商： </td>
		<td>
		 <input id="dealerCode" name="dealerCode" type="text" size="15" readonly="readonly" /> 
		<input type="button" id="button1" value="..."  class="mini_btn"  onclick="showOrgDealer('dealerCode','dealerId','false','','true','true')" /> 
		</td>
		<td width="27%"  align="right"><input type="radio" id="rd2" name=chngType value="2" onclick="checkSeconde();" />下级经销商： </td>
		<td>
		<select id="secondeDel__" name="secodeDel" onchange="chgDel();">
		<c:forEach items="${secondeDels }" var="secondeDels_A">
			<option value="${secondeDels_A.DEALER_ID }">${secondeDels_A.DEALER_NAME }-${secondeDels_A.DEALER_CODE }</option>
		</c:forEach>
		</select>
		</td>
	</tr>
	<tr>
		<td width="11%" align="right">批发原因：</td>
		<td width="25%"><textarea id="transfer_reason" name="transfer_reason"  datatype="0,is_textarea,300" ></textarea></td>
		
		<td width="37%" align="right"><input type="hidden" id="dealerId" name="dealerId" /><input name="button2" type="button" class="normal_btn" onclick="dispatch();" value="申请批发" /></td>
	</tr>
</table>
</form>
<script type="text/javascript">
	function clearTxt(value__A) {
		document.getElementById(value__A).value = "" ;
	}
	function checkFirst(){
		document.getElementById("button1").disabled=false;
		document.getElementById("secondeDel__").disabled=true;
		document.getElementById("dealerCode").disabled=false;
		clearTxt('dealerId') ;
	}
	function checkSeconde(){
		var sDealerId ;
		
		clearTxt('dealerCode') ;
		document.getElementById("secondeDel__").disabled=false;
		document.getElementById("dealerCode").disabled=true;
		document.getElementById("button1").disabled=true;
		sDealerId = document.getElementById('secondeDel__').value ;
		document.getElementById('dealerId').value = sDealerId ;
	}
	function chgDel() {
		var sDealerId ;

		sDealerId = document.getElementById('secondeDel__').value ;
		document.getElementById('dealerId').value = sDealerId ;
	}
	function toChangeMaterial(type){
		var materialCode = document.getElementById("materialCode");//物料组
		var materialCode__ = document.getElementById("materialCode__");//物料
		var bt1 = document.getElementById("bt1");
		var bt2 = document.getElementById("bt2");

		//选择物料组
		if(type==1){
			materialCode__.readOnly = true;
			materialCode__.value="";
			materialCode.readOnly = false;
			bt1.disabled  = false;
			bt2.disabled  = true;
		}else{
			materialCode.readOnly = true;
			materialCode.value="";
			materialCode__.readOnly=false;
			bt1.disabled  = true;
			bt2.disabled  = false;
		}
	}

	document.form1.style.display = "none";
	
	var HIDDEN_ARRAY_IDS=['form1'];

	var myPage;
	
	var url = "<%=contextPath%>/sales/storageManage/VehicleDispatch/VehicleDispatchList.json?COMMAND=1";
	
	var title = null;
	
	var columns = [
				{id:'action',header: "<input type='checkbox' name='checkAll' onclick='selectAll(this,\"vehicleIds\")' />", width:'6%',sortable: false,dataIndex: 'VEHICLE_ID',renderer:myCheckBox},
				{header: "VIN", dataIndex: 'VIN', align:'center'},
				{header: "车辆业务范围", dataIndex: 'AREA_NAME', align:'center'},
				{header: "发动机号", dataIndex: 'ENGINE_NO', align:'center'},
				{header: "车系", dataIndex: 'MATERIAL_NAME', align:'center'},
				{header: "车型", dataIndex: 'MODEL_NAME', align:'center'},
				{header: "物料代码", dataIndex: 'MATERIAL_CODE', align:'center'},
				{header: "物料名称", dataIndex: 'MATERIAL_NAME', align:'center'},
				{header: "验收日期", dataIndex: 'STORAGE_DATE', align:'center'},
				{header: "库存天数", dataIndex: 'STORAGE_DAY', align:'center'}
		      ];
		      
	function myCheckBox(value,metaDate,record){
		return String.format("<input type='checkbox' name='vehicleIds' value='" + value + "' />");
	}

	function dispatch(){
		var dealerCode = document.getElementById("dealerId").value;
		var transferreason = document.getElementById("transfer_reason").value;
		if(!dealerCode){
			MyAlert("请选择批发经销商");
			return;
		}
		if(transferreason.length<1){
			MyAlert("请填写批发原因！");
			return;
		}
		if (dealerCode == '${dlrId}') {
			clearTxt('dealerCode') ;
			clearTxt('dealerId') ;
			MyAlert("不能批发给当前经销商！");
			return;
		}
		var vehicleIds = document.getElementsByName("vehicleIds");
		var addFlag = false;
		for(var i=0; i<vehicleIds.length; i++){
			if(vehicleIds[i].checked){
				addFlag = true;
				break;
			}
		}
		if(addFlag){
			MyConfirm("是否提交?",dispatchAction);
		}else{
			MyAlert("请选择车辆信息!");
		}
	}

	function dispatchAction(){
		var vehicleIds_ = document.getElementsByName("vehicleIds");
		var vehicleIds="";//批发车辆
		if(vehicleIds_.length){
			for(var i=0; i<vehicleIds_.length; i++){
				if(vehicleIds_[i].checked == true){
					vehicleIds=vehicleIds+vehicleIds_[i].value+",";
		        }
			}
		}
		var dealerCode = document.getElementById("dealerId").value;//批发经销商
		var transfer_reason = document.getElementById("transfer_reason").value;//批发原因
		makeNomalFormCall('<%=contextPath%>/sales/storageManage/VehicleDispatch/vehicleDispatchSubmit.json?vehicleIds='+vehicleIds+'&dealerId='+dealerCode,showResult,'form1');
	}
	function showResult(json){
		if(json.returnValue == '1'){
			 __extQuery__(1);
		}else if(json.returnValue == '2'){
			var str = json.str;
			MyAlert("批发车辆"+str+"不符合调入方经销商的业务范围,不能批发！");
		}else if(json.returnValue == '3'){
			var myVinStr = json.myVinStr;
			MyAlert(myVinStr);
		}else{
			MyAlert("申请失败！请联系系统管理员！");
		}
		document.getElementById("dealerId").value = '' ;
		document.getElementById("dealerCode").value = "";
		document.getElementById("secondeDel__").value="";
		document.getElementById("transfer_reason").value = "";
	}
	function turnQuery() {
		
		
	}
</script>    
</body>
</html>